import React, { useState, useEffect } from 'react';
import { Table, Button } from 'antd';
import {request} from "../utils/requset";

const PDFListTable = () => {
    const [PDFList, setPDFList] = useState([]);

    useEffect(() => {
        fetchUsers();
    }, []);

    const fetchUsers = async () => {
        try {
            const response = await request.get('/rpa/pdf/list');
            setPDFList(response.data.data);
        } catch (error) {
            console.error('Error fetching users:', error);
        }
    };

    const columns = [
        {
            title: '文件名',
            dataIndex: 'fileName',
            key: 'fileName',
        },
        {
            title: '年',
            dataIndex: 'year',
            key: 'year',
        },
        {
            title: '月',
            dataIndex: 'month',
            key: 'month',
        },
        {
            title: '凭证号',
            dataIndex: 'pzh',
            key: 'pzh',
        },
        {
            title: '更新时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
        },
        {
            title: '操作',
            key: 'action',
            render: (text, record) => (
                <span>
                    <Button type="link" onClick={() => {request.get('/rpa/pdf/download?id='+record.id)}}>预览</Button>
                </span>
            ),
        },
    ];

    return (
        <div>
            <Table dataSource={PDFList} columns={columns} rowKey="id" />
        </div>
    );
};

export default PDFListTable;
